package com.zhen.aikan.controller;

import com.zhen.aikan.entity.VodDetail;
import com.zhen.aikan.service.IFavouriteService;
import com.zhen.aikan.vo.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author LiJiaZhen
 * @date 2023/9/25 10:34
 */
@RestController
@RequestMapping("/api/favourite")
public class FavouriteController {
    @Autowired
    private IFavouriteService favouriteService;

    @ApiOperation("添加收藏")
    @GetMapping("/addFavourite")
    public Result addFavourite(String userId,String vodId){
        boolean success = favouriteService.addFavourite(userId,vodId);
        return Result.ok(success?1:0);
    }

    @ApiOperation("取消收藏")
    @GetMapping("/delete")
    public Result deleteFavourite(String userId,String vodId){
        boolean success = favouriteService.deleteFavourite(userId,vodId);
        return Result.ok(success?1:0);
    }

    @ApiOperation("判断该视频是否是已收藏的")
    @GetMapping("/isFavourite")
    public Result isFavourite(String userId,String vodId){
        boolean success = favouriteService.isFavourite(userId,vodId);
        return Result.ok(success?1:0);
    }

    @ApiOperation("通过用户账户获取收藏")
    @GetMapping("/getFavourite")
    public Result getFavouriteByUserId(String userId){
        List<VodDetail> favouriteVodDetails = favouriteService.getFavouriteByUserId(userId);
        return Result.ok(favouriteVodDetails);
    }
}
